package com.heima.admin.controller.v1;

import com.heima.admin.dtos.ChannelDTO;
import com.heima.admin.pojos.AdChannel;
import com.heima.admin.service.ChannelService;
import com.heima.model.common.dtos.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * Description:
 */
@RestController
@RequestMapping("/api/v1/channel")
@Api(value = "频道管理", tags = "频道管理", description = "频道管理API")
public class ChannelController {

    @Autowired
    private ChannelService channelService;

    @PostMapping("/list")
    @ApiOperation(value = "频道分页查询",notes = "条件，频道名称，状态，以ord升序查询频道")
    @ApiImplicitParams(
            @ApiImplicitParam(value = "dto",dataType = "ChannelDTO",required = true)
    )
    public ResponseResult findByNameAndPage(@RequestBody ChannelDTO dto) {
        return channelService.findByNameAndPage(dto);
    }

    @PostMapping("/save")
    @ApiOperation(value = "频道新增")
    @ApiImplicitParams(
            @ApiImplicitParam(value = "dto",dataType = "ChannelDTO",required = true)
    )
    public ResponseResult saveChannel(@RequestBody AdChannel adChannel) {
        return channelService.insert(adChannel);
    }

    @PostMapping("/update")
    @ApiOperation(value = "频道修改")
    @ApiImplicitParams(
            @ApiImplicitParam(value = "dto",dataType = "ChannelDTO",required = true)
    )
    public ResponseResult updateChannel(@RequestBody AdChannel adChannel) {
        return channelService.update(adChannel);
    }

    @GetMapping("/del/{id}")
    @ApiOperation(value = "频道删除")
    @ApiImplicitParams(
            @ApiImplicitParam(value = "id",dataType = "Integer",required = true)
    )
    public ResponseResult saveChannel(@PathVariable("id") Integer id) {
        return channelService.deleteById(id);
    }


}
